package com.fms.gui.templateCreator.components.date.parts;

import junit.framework.TestCase;

import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.lib.legacy.ClassImposteriser;

import com.fms.TestUtils;
import com.fms.gui.templateCreator.components.date.ITimeInformer;

public class MinuteHandTest extends TestCase
{

	Mockery mock;
	
	protected void setUp() throws Exception
	{
		super.setUp();
		mock = new Mockery();
	}

	protected void tearDown() throws Exception
	{
		super.tearDown();
		mock.assertIsSatisfied();
	}
	
	
	public void testMinuteHandAtZero()
	{
		mock.setImposteriser(ClassImposteriser.INSTANCE);
		final ITimeInformer informer = mock.mock(ITimeInformer.class);
		final TimeAngleCalculator calc = mock.mock(TimeAngleCalculator.class);
		
		
		mock.checking(new Expectations()
		{{
			
			oneOf(calc).minuteToAngle(with(0)); will( returnValue(0.0));
			oneOf(informer).getMinute(); will(returnValue(0));			
		}});
		
		
		MinuteHand hand = new MinuteHand(informer, calc);
		
		assertTrue(hand.getAngle() == 0.0);		
	}
	
	
	public void testMinuteHandAtFiftenPast()
	{
		mock.setImposteriser(ClassImposteriser.INSTANCE);
		final ITimeInformer informer = mock.mock(ITimeInformer.class);
		final TimeAngleCalculator calc = mock.mock(TimeAngleCalculator.class);
		
		mock.checking(new Expectations()
		{{
			oneOf(calc).minuteToAngle(with(15)); will( returnValue(Math.PI/2.0));
			oneOf(informer).getMinute(); will(returnValue(15));			
		}});
				
		MinuteHand hand = new MinuteHand(informer, calc);
		
		assertTrue(TestUtils.aboutEqual(hand.getAngle(), Math.PI /2.0));		
	}

	
	public void testMinuteHandAtFiftenOf()
	{
		mock.setImposteriser(ClassImposteriser.INSTANCE);
		final ITimeInformer informer = mock.mock(ITimeInformer.class);
		final TimeAngleCalculator calc = mock.mock(TimeAngleCalculator.class);
		
		mock.checking(new Expectations()
		{{
			oneOf(calc).minuteToAngle(with(45)); will( returnValue(Math.PI * 3.0/2.0));
			oneOf(informer).getMinute(); will(returnValue(45));			
		}});
				
		MinuteHand hand = new MinuteHand(informer, calc);
		
		assertTrue(TestUtils.aboutEqual(hand.getAngle(), Math.PI * 3.0/2.0));		
	}
}
